﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Extend
{
    public static class AssemblyExtensions
    {
        public static List<Type> GetInheritedTypes(this Assembly assembly, Type baseType)
        {
            return assembly.GetTypes()
                .Where(x => x.BaseType != null && x.BaseType.GenericEq(baseType))
                .ToList();
        }
        public static SortedDictionary<string, string> ObjToSortedDictionary(object obj)
        {
            SortedDictionary<string, string> map = new SortedDictionary<string, string>();
            Type type = obj.GetType();
            foreach (PropertyInfo item in type.GetProperties())
            {
                map.Add(item.Name, item.GetValue(obj).ToString());
            }
            return map;
        }
    }
}
